
// import oimo.collision.geometry.*;
// import oimo.collision.narrowphase.*;
// import oimo.common.Transform;
// import oimo.m.Vec3;
// import oimo.m.M;

import { DetectorResult } from "../DetectorResult";
import { Vec3 } from "../../../common/Vec3";
import { DetectorResultPoint } from "../DetectorResultPoint";
import { Geometry } from "../../geometry/Geometry";
import { Transform } from "../../../common/Transform";
import { CachedDetectorData } from "./CachedDetectorData";

/**
 * numbererface of a collision detector for narrow-phase collision detection.
 */

export class Detector {
	swapped: boolean;


	constructor(swapped: boolean) {
		this.swapped = swapped;
	}

	// --- ---

	public setNormal(result: DetectorResult, n: Vec3): void {
		result.normal.copyFrom(n);
		if (this.swapped) {
			result.normal.negateEq();
		}
	}

	public addPoint(result: DetectorResult, pos1: Vec3, pos2: Vec3, depth: number, id: number): void {
		var p: DetectorResultPoint = result.points[result.numPoints++];
		p.depth = depth;
		p.id = id;
		if (this.swapped) {
			p.position1.copyFrom(pos2);
			p.position2.copyFrom(pos1);
		} else {
			p.position1.copyFrom(pos1);
			p.position2.copyFrom(pos2);
		}
	}

	public detectImpl(result: DetectorResult, geom1: Geometry, geom2: Geometry,
		tf1: Transform, tf2: Transform, cachedData: CachedDetectorData): void {
		//  this
	}

	// --- public ---

	/**
	 * Computes the contact manifold of two collision geometries `geom1` and `geom2` with the transforms
	 * `transform1` and `transform2`, and stores it to `result`. `cachedData` is used to improve performance
	 * of collision detection in some detectors.
	 */
	public detect(result: DetectorResult, geom1: Geometry, geom2: Geometry,
		transform1: Transform, transform2: Transform, cachedData: CachedDetectorData): void {
		result.clear();
		if (this.swapped) {
			this.detectImpl(result, geom2, geom1, transform2, transform1, cachedData);
		} else {
			this.detectImpl(result, geom1, geom2, transform1, transform2, cachedData);
		}
	}
}
